﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using Common.Aspects;

namespace Common.BaseClasses
{
    //[DataMemberAspect]
    [NotifyPropertyChangedAspect(AspectPriority = 0)]
    public class ModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        public virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));

            if (propertyName != Property.NameFor((ModelBase x) => x.IsDirty))
                IsDirty = true;
        }

        public bool IsDirty { get; protected set; }

        public virtual void ClearDirty()
        {
            IsDirty = false;
        }
    }
}
